class WeLibrary {
  static drawTransferCanvas(canvas, valueAndColorRamp) {
    const colorRamp = valueAndColorRamp.ColorRamp;

    const values = [];

    let i = colorRamp[0][3] === 0.0 ? 1 : 0;
    for (; i < colorRamp.length; i++) {
      const [r, g, b, a] = colorRamp[i]
      const color = `RGBA(${r},${g},${b},${a / 255})`
      const percent = i / (colorRamp.length - 1)
      values.push({ percent, color });
    }

    const ctx = canvas.getContext('2d');
    const vertical = canvas.height > canvas.width;
    if (vertical) {

    } else {
      const gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
      for (let j = 0; j < values.length; j++) {
        const { percent, color } = values[j]
        gradient.addColorStop(percent, color)
      }
      ctx.fillStyle = gradient;
      ctx.clearRect(0, 0, canvas.width, canvas.height)
      ctx.fillRect(0, 0, canvas.width, canvas.height);
    }

    return canvas;
  }
}

export default WeLibrary
